#include <string.h>
#include <stdlib.h>
#include "sikle.h"

NString NString_new(char* str, int size)
{
  char* data = (char*)malloc(size+1);
  NString nstring;
  
  nstring.size = size;
  nstring.data = data;
  data[size] = 0;

  if(str)
    strncpy(data, str, size);
  
  return nstring;
}

int NString_equal(NString ns, NString nd)
{
  if(ns.size != nd.size)
    return 0;

  return !strncmp(ns.data, nd.data, ns.size);
}

int NString_hash(NString ns)
{
  int size = ns.size;
  char* data = ns.data;
  int hash = 0;
  int i;
 
  for(i = 0; i <= size; i++) {
    hash += data[i];
  }

  hash %= 11;

  return hash;
}
